package com.tianqu.tms.entity;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.tianqu.tms.core.base.TmsEntity;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.dao.IntegralcardUpdateHistoryDao;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dto.IntegralcardUpdateHistoryDto;

/**
 * @author zhangxueliang
 * 积分卡变更记录表 entity
 */
public class IntegralcardUpdateHistory extends TmsEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 8053817006578583520L;
	//会员ID
	private String memberId;
	//会员类型
	private int memberType;
	
	//业务类型
	private int businessType;
	private String businessTypeS;
	//旧积分卡编号
	private String accessCardIdOld;
	//旧积分卡卡号
	private String accessCardNoOld;
	//新积分卡编号
	private String accessCardIdNew;
	//新原积分卡卡号
	private String accessCardNoNew;
	//缴费
	private int changePrice;
	//备注
	private String remarks;
	//插入时间
	private Timestamp insertTime;
	private String insertTimeS;
	//插入用户
	private int insertUserId;
	private String insertName;
	
	private int cssFlag;//1,2区别（列表样式灰白区分）
	private int num;//列表的序号
	
	public static IntegralcardUpdateHistory getInstance() {
		IntegralcardUpdateHistory integralcardUpdateHistory = new IntegralcardUpdateHistory();
		integralcardUpdateHistory.setExisting(false);
		return integralcardUpdateHistory;
	}
	
	
	/**
	 * 插入信息
	 * @param entity
	 * @throws TmsDaoException 
	 */
	public void insertHistory(IntegralcardUpdateHistory entity) throws TmsDaoException{
		IntegralcardUpdateHistoryDao dao = (IntegralcardUpdateHistoryDao) TmsDao.getInstance(TmsDao.TMS_INTEGRALCARD_UPDATE_HISTORY);
		IntegralcardUpdateHistoryDto dto = new IntegralcardUpdateHistoryDto();
		dto.setMemberId( entity.getMemberId());
		dto.setMemberType( entity.getMemberType());
		dto.setBusinessType( entity.getBusinessType());
		dto.setAccessCardIdOld( entity.getAccessCardIdOld());
		dto.setAccessCardNoOld(entity.getAccessCardNoOld());
		dto.setAccessCardIdNew(entity.getAccessCardIdNew());
		dto.setAccessCardNoNew(entity.getAccessCardNoNew());
		dto.setChangePrice( entity.getChangePrice());
		dto.setRemarks(entity.getRemarks());
		dto.setInsertUserId(entity.getInsertUserId());
		dao.insertHistory(dto);
	}
	
	
	/**
	 * 根据memId载入历史记录
	 * @param memId
	 * @return
	 * @throws TmsDaoException
	 */
	@SuppressWarnings("unchecked")
	public List findHistoryByMemId(String memId)throws TmsDaoException{
		List<IntegralcardUpdateHistoryDto> integralHistoryList = new ArrayList<IntegralcardUpdateHistoryDto>();
		IntegralcardUpdateHistoryDao dao = (IntegralcardUpdateHistoryDao) TmsDao.getInstance(TmsDao.TMS_INTEGRALCARD_UPDATE_HISTORY);
		integralHistoryList = dao.findIntegralHistory(memId);
		List historyList = new ArrayList();
		int i = 1;
		for(IntegralcardUpdateHistoryDto dto : integralHistoryList){
			IntegralcardUpdateHistory entity = new IntegralcardUpdateHistory();
			entity.setNum(i);
			if(i%2!=0){//样式
				entity.setCssFlag(1);
			}else{
				entity.setCssFlag(2);
			}
			if(dto.getBusinessType() == 1){
				entity.setBusinessTypeS("首次发卡");
				entity.setAccessCardIdNew("-");
				entity.setAccessCardNoNew("-");
			}else if(dto.getBusinessType() == 2){
				entity.setBusinessTypeS("换卡/补卡");
				entity.setAccessCardIdNew(dto.getAccessCardIdNew());
				entity.setAccessCardNoNew(dto.getAccessCardNoNew());
			}

			entity.setAccessCardIdOld(dto.getAccessCardIdOld());
			entity.setAccessCardNoOld(dto.getAccessCardNoOld());
			User user = User.getInstance();
			user = user.getUserInfoById(dto.getInsertUserId());
			if(user != null){
				entity.setInsertName(user.getRealName());
			}
			entity.setInsertTimeS(DateUtil.getDateByTimeStampHM(dto.getInsertTime()));
			if(StringUtil.isNullOrBlank(dto.getRemarks())){
				entity.setRemarks("-");
			}else{
				entity.setRemarks(dto.getRemarks());
			}
			
			historyList.add(entity);
			i++;
		}
		return historyList;
	}
	public String getMemberId() {
		return memberId;
	}
	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}
	public int getMemberType() {
		return memberType;
	}
	public void setMemberType(int memberType) {
		this.memberType = memberType;
	}
	public int getBusinessType() {
		return businessType;
	}
	public void setBusinessType(int businessType) {
		this.businessType = businessType;
	}
	public String getAccessCardIdOld() {
		return accessCardIdOld;
	}
	public void setAccessCardIdOld(String accessCardIdOld) {
		this.accessCardIdOld = accessCardIdOld;
	}
	public String getAccessCardNoOld() {
		return accessCardNoOld;
	}
	public void setAccessCardNoOld(String accessCardNoOld) {
		this.accessCardNoOld = accessCardNoOld;
	}
	public String getAccessCardIdNew() {
		return accessCardIdNew;
	}
	public void setAccessCardIdNew(String accessCardIdNew) {
		this.accessCardIdNew = accessCardIdNew;
	}
	public String getAccessCardNoNew() {
		return accessCardNoNew;
	}
	public void setAccessCardNoNew(String accessCardNoNew) {
		this.accessCardNoNew = accessCardNoNew;
	}
	public int getChangePrice() {
		return changePrice;
	}
	public void setChangePrice(int changePrice) {
		this.changePrice = changePrice;
	}
	public String getRemarks() {
		return remarks;
	}
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}
	public Timestamp getInsertTime() {
		return insertTime;
	}
	public void setInsertTime(Timestamp insertTime) {
		this.insertTime = insertTime;
	}
	public int getInsertUserId() {
		return insertUserId;
	}
	public void setInsertUserId(int insertUserId) {
		this.insertUserId = insertUserId;
	}


	@Override
	public void save() throws TmsDaoException, TmsException {
		// TODO Auto-generated method stub
		
	}


	public int getCssFlag() {
		return cssFlag;
	}


	public void setCssFlag(int cssFlag) {
		this.cssFlag = cssFlag;
	}


	public int getNum() {
		return num;
	}


	public void setNum(int num) {
		this.num = num;
	}


	public String getBusinessTypeS() {
		return businessTypeS;
	}


	public void setBusinessTypeS(String businessTypeS) {
		this.businessTypeS = businessTypeS;
	}


	public String getInsertTimeS() {
		return insertTimeS;
	}


	public void setInsertTimeS(String insertTimeS) {
		this.insertTimeS = insertTimeS;
	}


	public String getInsertName() {
		return insertName;
	}


	public void setInsertName(String insertName) {
		this.insertName = insertName;
	}
	
	
	
}
